package com.befiv.lock.config;

import com.befiv.lock.annotation.Lock;
import lombok.NonNull;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

/**
 * @Author: Gjq
 * @Date: 2019/6/28 0028 上午 9:43
 */
public class LockAnnotationAdapter extends AbstractPointcutAdvisor {
    private Pointcut pointcut;
    private Advice advice;

    public LockAnnotationAdapter(@NonNull LockMethodInterceptor advice) {
        this.pointcut = buildPointcut();
        this.advice = advice;
    }

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    @Override
    public Advice getAdvice() {
        return this.advice;
    }

    private Pointcut buildPointcut(){
        return AnnotationMatchingPointcut.forMethodAnnotation(Lock.class);
    }

}
